// todo 将这个改为插入 selection 的 插件
tinymce.PluginManager.add('customSelection', function (editor, url) {
  var openDialog = function () {
    var thisEdit = tinymce.activeEditor;
    var dom = thisEdit.dom;
    var body = thisEdit.getBody();
    var select = document.createElement("option");
    select.innerText = "asdf";
    select.setAttribute("value", "1");
    var test = dom.add(body, "select", {}, select);
    console.log(test);
    var selectedBlocks = thisEdit.selection.getSelectedBlocks();
    if (!(selectedBlocks && selectedBlocks.length)) {
      return
    }
    var lastNode = selectedBlocks[selectedBlocks.length - 1];
    lastNode.style.display = "inline-block";
    var test2 = dom.add(body, "p");
    test2.style.display = "inline-block";
    console.log(test2);
  };

  // 注册一个工具栏按钮名称
  editor.ui.registry.addButton('customSelection', {
    text: '自定义选择框',
    onAction: function (dialogApi, actionData) {
      console.log(arguments);
      openDialog();
    }
  });

  // 注册一个菜单项名称 menu/menubar
  editor.ui.registry.addMenuItem('customSelection', {
    text: 'Example菜单名',
    onAction: function () {
      openDialog();
    }
  });

  return {
    getMetadata: function () {
      return {
        //插件名和链接会显示在“帮助”→“插件”→“已安装的插件”中
        name: "Example plugin",//插件名称
        url: "http://exampleplugindocsurl.com", //作者网址
      };
    }
  };
});

